package com.yunti.business.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yunti.business.mapper.BaseUnitMapper;
import com.yunti.business.domain.BaseUnit;
import com.yunti.business.service.IBaseUnitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
 * 单位Service业务层处理
 *
 * @author yangtt
 * @date 2024-11-22
 */
@Service
public class BaseUnitServiceImpl   extends ServiceImpl<BaseUnitMapper, BaseUnit> implements IBaseUnitService{
    @Autowired
    private BaseUnitMapper baseUnitMapper;

    /**
     * 查询单位
     *
     * @param id 单位主键
     * @return 单位
     */
    @Override
    public BaseUnit selectBaseUnitById(Long id)
    {
        return baseUnitMapper.selectBaseUnitById(id);
    }

    /**
     * 查询单位列表
     *
     * @param baseUnit 单位
     * @return 单位
     */
    @Override
    public List<BaseUnit> selectBaseUnitList(BaseUnit baseUnit)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        baseUnit.setRaceId(loginUser.getSelectRaceId());
        return baseUnitMapper.selectBaseUnitList(baseUnit);
    }

    /**
     * 新增单位
     *
     * @param baseUnit 单位
     * @return 结果
     */
    @Override
    public int insertBaseUnit(BaseUnit baseUnit)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        baseUnit.setRaceId(loginUser.getSelectRaceId());
        baseUnit.setCreateTime(LocalDateTime.now());
        return baseUnitMapper.insertBaseUnit(baseUnit);
    }

    /**
     * 修改单位
     *
     * @param baseUnit 单位
     * @return 结果
     */
    @Override
    public int updateBaseUnit(BaseUnit baseUnit)
    {
        baseUnit.setUpdateTime(LocalDateTime.now());
        return baseUnitMapper.updateBaseUnit(baseUnit);
    }

    /**
     * 批量删除单位
     *
     * @param ids 需要删除的单位主键
     * @return 结果
     */
    @Override
    public int deleteBaseUnitByIds(Long[] ids)
    {
        return baseUnitMapper.deleteBaseUnitByIds(ids);
    }

    /**
     * 删除单位信息
     *
     * @param id 单位主键
     * @return 结果
     */
    @Override
    public int deleteBaseUnitById(Long id)
    {
        return baseUnitMapper.deleteBaseUnitById(id);
    }
}
